// 首先构建领接表
// 然后使用dfs遍历每个方法, 计算获取的食物, 食物需要缓存
// 每阶段食物最大值: 考虑是否加入子元素最大值
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n;
let initArr = [];
rl.on("line", (line)=>{
    if(n === undefined) {
        n = Number(line.trim())
    } else {
        initArr.push(line.trim().split(" ").map(Number))
        if(initArr.length === n) {
            console.log(getResult(n, initArr))

            // clear
            n = undefined
            initArr.length = 0
        }
    }

})

function getResult(n, initArr) {
    // 构建邻接表
    let obj = {}
    for (let i = 0; i < n ; i++) {
        obj[i] = {
            child: [],
            value: 0,
        }
    }
    obj[-1] = {
        child: [],
        value: 0,
    }
    for (const [id, parentId, value] of initArr) {
        obj[id].value = value
        obj[parentId].child.push(id)
    }

    // 遍历dfs
    let valueObj = {} // 缓存
    let ans = -Infinity;
    let arr = Object.keys(obj)
    for (const num of arr) {
        ans = Math.max(ans, dfs(num, obj, valueObj))
    }

    // return
    return ans
}

function dfs(num, obj, valueObj) {
    if(valueObj[num] !== undefined){
        return valueObj[num]
    }

    let value = obj[num].value
    let temp = -Infinity
    let childArr = obj[num].child
    for (const id of childArr) {
        let value = dfs(id, obj, valueObj)
        valueObj[id] = value
        temp = Math.max(value, temp)
    }
    return Math.max(value, temp + value)
}